<?php
if( !defined( 'GENERIQUENL' ) ): define( 'GENERIQUENL', 1 );
if( !defined( 'FILE_ROOT' ) ) include_once( '../path.conf' );


/**
 * Table Newsletter
 */
USE_APP('Newsletter');
class GeneriqueNL implements NewsletterBuilder
	{
	public function buildForm( $form )
		{
		$f = $form->add( new FormFieldInput( 'f_title', true ) );
		$f = $form->add( new FormFieldHtmlEdit( 'f_text', false ) );
		}

	public function elt2html( $tpl, $elt, $prefix )
		{
		$tpl->setVarText( $prefix . 'F_TITLE', ARRAYVAL( $elt, 'f_title' ) );
		$tpl->setVarText( $prefix . 'F_TEXT', ARRAYVAL( $elt, 'f_text' ) );
		}

	public function elt2htmlPHP( &$elt )
		{
		}

	public function setSearchFields( &$sproc )
		{
		$sproc->addField('f_title');
		$sproc->addField('f_text');
		}
		
	public function getSearchParams()
		{
		return array(
				'title'=>'Title',
				'head' => '{VAR_F_TITLE}',
				'body' => '{VAR_F_TEXT}',
				);
		}
		
	public function getDisplayDepth() {return 1;}
		
	public function build( $id, Template $tpl )
		{
		}
		
	public function getTplFilename()
		{
		return( APP_ROOT . 'generiquenl.tpl' );
		}
		
	public function getAddresses()
		{
		USE_APP( 'newsletter_inscrits' );
		$site = new Newsletter_inscrits;
		$site_emails = $site->getColumnByParams( 'f_email', array(
			SQL::WHERE => 'f_status>=1',
			SQL::ORDER => 'f_email asc'
			) );
		$alls = array_unique( $site_emails );
		return $alls;
		}
		
	public function getName( $elt )
		{
		return ARRAYVAL( $elt, 'f_title' ) . ' - ' . SITE_NAME;
		}

	public function beforeSend( $eml, $email, $is_test )
		{
		$site = new Newsletter_inscrits;
		$elt = $site->getElementByField( 'f_email', $email );
		$prefix = 'PEOPLE_';
		$eml->setVarDate( $prefix . 'F_DATE', ARRAYVAL( $elt, 'f_date' ) );
		$eml->setVarText( $prefix . 'F_NOM', ARRAYVAL( $elt, 'f_nom' ) );
		$eml->setVarText( $prefix . 'F_PRENOM', ARRAYVAL( $elt, 'f_prenom' ) );
		$eml->setVarText( $prefix . 'F_TELEPHONE', ARRAYVAL( $elt, 'f_telephone' ) );
		$eml->setVarAddress( $prefix . 'F_ADRESSE', ARRAYVAL( $elt, 'f_adresse' ) );
		$eml->setVarText( $prefix . 'F_EMAIL', ARRAYVAL( $elt, 'f_email' ) );
		}
	}
endif;
?>